package com.zengdb.mybatis.service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.zengdb.mybatis.dao.TeacherMapper;
import com.zengdb.mybatis.domain.Student;
import com.zengdb.mybatis.domain.Teacher;
import com.zengdb.mybatis.service.ITeacherService;
import com.zengdb.mybatis.util.MyBatisUtil;

public class TeacherServiceImpl implements ITeacherService{

	@Override
	public void saveOne(Teacher teacher) {
		SqlSession session = MyBatisUtil.openSession();
		TeacherMapper dao = session.getMapper(TeacherMapper.class);
		dao.saveOne(teacher);
		session.commit();
		session.close();
	}
	
	@Override
	public void saveRelationWithStudent(Long teacherId, Long studentId) {
		SqlSession session = MyBatisUtil.openSession();
		TeacherMapper dao = session.getMapper(TeacherMapper.class);
		dao.saveRelationWithStudent(teacherId, studentId);
		session.commit();
		session.close();
	}

	@Override
	public void saveRelationWithMultiStudents(Long teacherId, List<Student> students) {
		SqlSession session = MyBatisUtil.openSession();
		TeacherMapper dao = session.getMapper(TeacherMapper.class);
		dao.saveRelationWithMultiStudents(teacherId, students);
		session.commit();
		session.close();
	}

	
}
